﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AccessModel;
using DBUtility;
using MySql.Data.MySqlClient;
using System.Data;

namespace AccessDAL
{
    public class MenuDAL
    {
        #region
        public int createUser(Menu menu)
        {
            string sql = "insert into menu (menuname,menulink,menutarget) values ('" + menu.menuname + "', '" + menu.menulink + "','" + menu.menutarget + "')";
            int i = 0;
            try
            {
                i = DBUtility.MySqlHelper.ExecuteSql(sql);
            }
            catch (Exception e)
            {
                throw e;
            }
            return i;

        }
        #endregion

        #region Select all users.
        public static List<Menu> QueryMenus()
        {
            //string sql = "SELECT * FROM TAB_USER";
            string sql = "select * from menu order by id asc";
            List<Menu> mList = new List<Menu>();

            try
            {
                MySqlDataReader reader = DBUtility.MySqlHelper.ExecuteReader(sql, null);
                while (reader.Read())
                {
                    Menu menu = new Menu();
                    menu.id = Convert.ToInt32(reader["id"].ToString());
                    menu.menuname = reader["menuname"].ToString();
                    menu.menulink = reader["menulink"].ToString();
                    menu.menutarget = reader["menutarget"].ToString();
                    menu.menudate = Convert.ToDateTime(reader["menudate"].ToString());

                    mList.Add(menu);

                }
                reader.Dispose();
                reader.Close();

            }
            catch (Exception e)
            {

                return null;
            }


            return mList;
        }
        #endregion
    }
}
